<template>
  <div class="head flex flex-center" :style="{ width, height }">
    <div class="title">{{ title }}</div>
  </div>
  <div class="today f18 fWhite">{{ time }}</div>
</template>

<script setup lang="ts">
import moment from 'moment'
import { ref, onMounted, onBeforeUnmount } from 'vue'

defineProps({
  title: {
    type: String,
    defulat: '广东劳易多科技有限公司',
  },
  color: {
    type: String,
    defulat: '#fff',
  },
  width: {
    type: String,
    defulat: '100%',
  },
  height: {
    type: String,
    defulat: '5.7rem',
  },
})

//存储当前时间
let time = ref(moment().format('YYYY-MM-DD hh:mm:ss'))
//定时器id
let timer = ref(0)

onMounted(() => {
  timer.value = setInterval(() => {
    time.value = moment().format('YYYY-MM-DD hh:mm:ss')
  }, 1000)
})

onBeforeUnmount(() => {
  //组件销毁之前将定时器移除
  clearInterval(timer.value)
})
</script>

<style scoped>
.flex {
  display: flex;
}
.flex-center {
  justify-content: center;
}
.head {
  background: url(/src/assets/images/head/head1.jpg) no-repeat top;
  height: 5.7rem;
  line-height: 6rem;
}
.title {
  font-size: 2em;
  color: white;
}
.today {
  position: absolute;
  right: 2%;
  top: 1.625rem;
  background: url(/src/assets/images/head/time.png) no-repeat 0;
  text-indent: 2rem;
  line-height: 25px;
}
</style>
